/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.transformation.editor.model.pattern;

// imports:
import org.w3c.dom.Element;

import edu.pku.sei.modeler.model.common.MetaTypedList;
import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.xml.XMLUtility;
import edu.pku.sei.transformation.editor.model.Domain;
import edu.pku.sei.transformation.editor.model.GraphicalDomain;
import edu.pku.sei.transformation.editor.model.ModelPackage;

/**
 * @generated
 * 
 */
public class Pattern extends MetaModelElement {
	private MetaTypedList nodes;
	private MetaTypedList links;
	private GraphicalDomain owner;

	public Domain getOwner() {
		return owner;
	}

	public void setOwner(GraphicalDomain owner) {
		this.owner = owner;
	}

	public MetaTypedList getNodes() {
		if (nodes == null) {
			nodes = new MetaTypedList(INodeTemplate.class, this,
					ModelPackage.PATTERN_NODES);
		}
		return nodes;
	}

	public void setNodes(MetaTypedList nodes) {
		this.nodes = nodes;
	}

	public MetaTypedList getLinks() {
		if (links == null) {
			links = new MetaTypedList(ILinkTemplate.class, this,
					ModelPackage.PATTERN_LINKS);
		}
		return links;
	}

	public void setLinks(MetaTypedList links) {
		this.links = links;
	}

	// save & load
	public void serialize(Element root) {
		super.serialize(root);
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.PATTERN_NODES,
				this.nodes);
		XMLUtility.xmlInstance.serializeNodes(root, ModelPackage.PATTERN_LINKS,
				this.links);
		XMLUtility.xmlInstance.serializeNodeNotContain(root,
				ModelPackage.PATTERN_OWNER, this.owner);
	}

	public void deSerialize(Element root) {
		super.deSerialize(root);
		this.getNodes().addAll(
				XMLUtility.xmlInstance.deSerializeNodes(root,
						ModelPackage.PATTERN_NODES));
		this.getLinks().addAll(
				XMLUtility.xmlInstance.deSerializeNodes(root,
						ModelPackage.PATTERN_LINKS));
		this.setOwner((GraphicalDomain) XMLUtility.xmlInstance
				.deSerializeNodeNotContain(root, ModelPackage.PATTERN_OWNER,
						this));

	}

	public void dynamicSet(String featureID, Object value) {
		if (featureID == null || "".equals(featureID)) {
			return;
		}
		// attributes
		else if (ModelPackage.PATTERN_OWNER.equals(featureID)) {
			this.setOwner((GraphicalDomain) value);
		}
		// references

		else
			super.dynamicSet(featureID, value);
	}
}
